<template>
    <!-- components/activity_joinMask/activity_joinMask.wxml -->
    <view class="Mask" v-if="joinShow">
        <view class="maskContain">
            <view class="maskTip">
                <text v-if="specialActivity.creditcost">注意，参加此活动需要扣除{{ specialActivity.creditcost }}</text>
            </view>
            <view class="closeView" @tap.stop.prevent="closeMask">
                <image class="close" :src="minImgDoc + 'coures_join_close.png'"></image>
            </view>
            <view class="maskContent">
                <form @submit="formSubmit" :report-submit="true" report-submit-timeout="500">
                    <block v-for="(item, index) in joinfield" :key="index">
                        <view class="inputCell">
                            <view class="subtitle">
                                <text>*</text>
                                {{ item.title }}：
                            </view>
                            <input class="maskInput" :name="item.fieldid" :placeholder="'请输入' + item.title" />
                        </view>
                    </block>
                    <view class="inputCell">
                        <view class="subtitle">留言：</view>
                        <input class="maskInput" name="message" placeholder="请输入留言" />
                    </view>
                    <button class="weui-btn join-btn" type="primary" form-type="submit">立即报名</button>
                </form>
            </view>
        </view>
    </view>
</template>

<script>
// components/activity_joinMask/activity_joinMask.js
const minImgDoc = require('../../config').minImgDoc;

const activityAppliesUrl = require('../../config').activityAppliesUrl;

const app = getApp();
export default {
    data() {
        return {
            minImgDoc: minImgDoc,
            joinShow: true,
            specialActivity: {},
            joinfield: {},
            acPostData: {},
        };
    },
    /**
     * 组件的属性列表
     */
    props: {
        joinShow: {
            type: Boolean
        },
        specialActivity: {
            type: Object
        },
        acPostData: {
            type: Object
        }
    },
    /**
     * 组件的方法列表
     */
    methods: {

        closeMask() {
            this.joinShow= false
        },

        formSubmit(e) {
            uni.showLoading({
                title: '正在报名',
                icon: 'loading'
            });
            console.log(this.acPostData);
            var dic = e.detail.value;
            dic['tid'] = this.acPostData.tid;
            dic['fid'] = this.acPostData.fid;
            dic['pid'] = this.acPostData.pid;
            dic['formhash'] = app.globalData.formhash;
            dic['activitysubmit'] = true;
            app.globalData.apimanager
                .postRequest(activityAppliesUrl, dic)
                .then((res) => {
                    uni.hideLoading();

                    if (res.Message.messageval == 'activity_completion') {
                        this.joinShow= false
                        this.$emit('joinSucceed');
                    }

                    uni.showModal({
                        content: res.Message.messagestr,
                        showCancel: false,
                        confirmText: '知道了'
                    });
                })
                .catch((res) => {
                    uni.hideLoading();
                });
        }
    }
}
</script>
<style>
@import './activity_joinMask.css';
</style>
